package com.cgbl.cg.ui.splash

import android.os.Bundle
import android.text.TextUtils
import com.cgbl.cg.R
import com.cgbl.cg.databinding.AppActivitySplashBinding
import com.cgbl.cg.im.ImManager
import com.cgbl.cg.im.ImManager.LoginListener
import com.cgbl.cg.vm.splash.SplashViewModel
import com.robot.base.base.activity.GLBaseActivity
import com.robot.base.configs.AppConstants
import com.robot.base.configs.PrefsManager
import com.robot.base.util.arouter.ARouterUtil
import me.goldze.mvvmhabit.BR

/**
 * 启动页
 */
class SplashActivity : GLBaseActivity<AppActivitySplashBinding, SplashViewModel>() {

    override fun initContentView(savedInstanceState: Bundle?): Int = R.layout.app_activity_splash

    override fun initVariableId(): Int = BR.viewModel

    override fun initComponents() {
        val token = PrefsManager.getUserLoginInfo().accessToken
        if (TextUtils.isEmpty(token)) {
            ARouterUtil.goToActivity(AppConstants.Router.Main.A_MAIN)
            finish()
            return
        }
        val account = PrefsManager.getUserInfo().accid;
        val imToken = PrefsManager.getUserInfo().imToken
        ImManager.startLogin(account, imToken, object : LoginListener {
            override fun loginSuccess() {
                ARouterUtil.goToActivity(AppConstants.Router.Main.A_MAIN)
                finish()
            }

            override fun loginFailed() {
                ARouterUtil.goToActivity(AppConstants.Router.Login.A_LOGIN_PASSWORD)
                finish()
            }
        })

    }

}